#!/bin/bash -e
source reporting.sh

PORT=10000
REPORT=/tmp/report.txt

TEST_NAME="security.brute"
TEST_DESCRIPTION="Educational test - not to be included in a production environment!"
TEST_SUMMARY=""
LOG=/tmp/brute.log

nc -vnz $TARGET_IP -w 2 $PORT || true
sleep 2
nc -vnz $TARGET_IP -w 2 $PORT || true
sleep 2

if nc -nz $TARGET_IP -w 2 $PORT; then
    sleep 3
    result=fail
    python -u brute_client.py $TARGET_IP $PORT $LOG && result=pass

    if [ "$result" == fail ]; then
        TEST_SUMMARY="Change the default password on the DUT"
    fi

else
    echo Target port $PORT not open. | tee -a $LOG
    result=skip
    TEST_SUMMARY="Port $PORT is not open"
fi

RESULT_AND_SUMMARY="RESULT $result $TEST_NAME $TEST_SUMMARY"

write_out_result $REPORT \
                 "$TEST_NAME" \
                 "$TEST_DESCRIPTION" \
                 "$(cat $LOG)" \
                 "$RESULT_AND_SUMMARY"

